package com.compass.mobile.ui.adapter

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.compass.mobile.R
import com.compass.mobile.callback.OnCustomButtonClick
import com.compass.mobile.databinding.LayoutDeptItemBinding
import com.compass.mobile.databinding.LayoutTextMessageItemBinding
import com.compass.mobile.framework.adapter.BaseBindViewHolder
import com.compass.mobile.framework.adapter.BaseMultiItemAdapter
import com.compass.mobile.framework.ext.gone
import com.compass.mobile.framework.ext.onClick
import com.compass.mobile.framework.ext.visible
import com.compass.mobile.models.AIMessageInfo
import com.compass.mobile.models.SuggestMessageInfo
import getDrawableResource
import saveAs

/**
 * Description： 投诉建议adapter
 * Date:2024/7/12 14:17
 */
class SuggestMessageAdapter : BaseMultiItemAdapter<SuggestMessageInfo>() {

    private lateinit var onCustomButtonClick: OnCustomButtonClick
    fun setBottomCallBack(onChatBottomClick: OnCustomButtonClick) {
        this.onCustomButtonClick = onChatBottomClick
    }

    //用来实现多item布局
    override fun getDefItemViewType(position: Int): Int {
        val info = getData()[position]
        return info.sendType
    }


    @SuppressLint("SetTextI18n")
    override fun onBindDefViewHolder(
        holder: BaseBindViewHolder<ViewBinding>,
        item: SuggestMessageInfo?,
        position: Int
    ) {
        if (item == null) return
        val binding = holder.binding.saveAs<LayoutTextMessageItemBinding>()
        binding.apply {

            when (item.sendType) {
                1 -> {
                    imgHeader.setBackgroundResource(R.mipmap.default_head)
                    leftLayout.visible()
                    rightLayout.gone()
                    leftMsg.text = item.content
                }

                2 -> {
                    rightLayout.visible()
                    leftLayout.gone()
                    rightMsg.text = item.content

                }
            }
        }

    }


    override fun getViewBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): ViewBinding {
        return when (viewType) {

            1 -> {
                LayoutTextMessageItemBinding.inflate(layoutInflater, parent, false)
            }

            else -> {
                LayoutTextMessageItemBinding.inflate(layoutInflater, parent, false)
            }
        }

    }
}